package aufgabe1;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;

public class AdjacencyList extends AdjacencyStructure {

	protected AdjacencyList(Graph g) {
		super(g);

	}

	@Override
	public void print() {
		super.print();

		for (int i = 1; i < _g.getList().length; i++) {
			System.out.print(_g.getVertice(i).getPos() + " -> ");

			for (int j = 0; j < _g.getList()[i - 1].size(); j++) {

				System.out.println("["
						+ _g.getList()[i - 1].get(j).getEnd().getPos() + ", "
						+ _g.getList()[i - 1].get(j).getVlaue() + "]");

			}
		}
		System.out.println();

	}

	@Override
	public ArrayList<Vertice> getNeighbours(int key) {

		LinkedList<Edge> temp = _g.getList()[key - 1];
		ArrayList<Vertice> nodes = new ArrayList();
		Iterator<Edge> it = temp.listIterator();
		while (it.hasNext()) {
			Edge e = it.next();
			nodes.add(e.getEnd());
		}
		return nodes;
	}
}